package com.eddie.community.util;

import com.eddie.community.entity.User;
import org.springframework.stereotype.Component;

/**
 * ClassName: HostHolder
 * Package: com.eddie.community.util
 * Description:代替session持有session，方便多线程调用
 * Date: 2021/2/8 0008 18:29
 * Author: eddie_zhan@yeah.net
 */
@Component
public class HostHolder {
    private ThreadLocal<User> userThreadLocal = new ThreadLocal<>();

    public void setUser(User user) {
        userThreadLocal.set(user);
    }

    public User getUser() {
        return userThreadLocal.get();
    }

    public void clear() {
        userThreadLocal.remove();
    }

}
